/*
 * Copyright © 2021 尛飛俠（Denvie） All rights reserved.
 */

package cn.denvie.springboot.mbp.generator.properties;

import com.google.common.base.Splitter;
import lombok.Getter;

import java.io.IOException;
import java.util.Properties;

/**
 * 代码生成配置属性。
 *
 * @author Denvie
 * @date 2021/12/18
 * @since 1.0.0
 */
@Getter
public class GenerateProperties {
    private final String author;
    private final String version;
    private final String copyright;

    private final String url;
    private final String username;
    private final String password;

    private final String projectName;
    private final String packageName;
    private final String moduleName;
    private final String entityPkg;
    private final String mapperPkg;
    private final String mapperXmlPkg;
    private final String servicePkg;
    private final String serviceImplPkg;
    private final String controllerPkg;

    private final String javaOutputDir;
    private final String xmlOutputDir;

    private final String[] includeTables;
    private final String tablePrefix;

    public GenerateProperties(String fileName) {
        try {
            Properties properties = new Properties();
            properties.load(this.getClass().getClassLoader().getResourceAsStream(fileName));
            this.author = properties.getProperty("author");
            this.version = properties.getProperty("version");
            this.copyright = properties.getProperty("copyright");

            this.url = properties.getProperty("url");
            this.username = properties.getProperty("username");
            this.password = properties.getProperty("password");

            this.projectName = properties.getProperty("projectName");
            this.packageName = properties.getProperty("packageName");
            this.moduleName = properties.getProperty("moduleName");
            this.entityPkg = properties.getProperty("entityPkg");
            this.mapperPkg = properties.getProperty("mapperPkg");
            this.mapperXmlPkg = properties.getProperty("mapperXmlPkg");
            this.servicePkg = properties.getProperty("servicePkg");
            this.serviceImplPkg = properties.getProperty("serviceImplPkg");
            this.controllerPkg = properties.getProperty("controllerPkg");

            this.javaOutputDir = properties.getProperty("javaOutputDir");
            this.xmlOutputDir = properties.getProperty("xmlOutputDir");

            this.includeTables = Splitter.on(",")
                    .trimResults()
                    .omitEmptyStrings()
                    .splitToList(properties.getProperty("includeTables"))
                    .toArray(new String[]{});
            this.tablePrefix = properties.getProperty("tablePrefix");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
